/** @jsxImportSource @emotion/react */
import * as React from "react";
import {InputLine,  BlobInputList,} from "customize-easy-ui-component";
import {
    InspectRecordLayout, InternalItemProps, useInputControlSure,
} from "../common/base";
import {useMeasureInpFilter} from "../common/hooks";
import {EditStorageContext} from "../StorageContext";
import {useUppyUpload} from "../hook/useUppyUpload";

interface Props  extends InternalItemProps{
    label?: string;
    maxFile?:number;
    memc?: string;
    datalist?: string[];
}
export const itemA附页附=['示图说明','_FILE_S部位'];
//只能上不变的：不然hook死循环
// const defaultValCb= (par: { 检测结果?: any; })=>{
//     const { 检测结果 }=par||{};
//     if(!检测结果)   par.检测结果='所检项目未见异常，检测结果为1级。';
//     return  par;
// }
export const AttachedFigure=
React.forwardRef((
    { children, show ,alone=true,redId,nestMd, repId,datalist,maxFile=10,label,memc}:Props,  ref
) => {
    const {modified,setModified,} =React.useContext(EditStorageContext) as any;
    const [getInpFilter] = useMeasureInpFilter(null, itemA附页附, );
    const {inp, setInp,onSure} = useInputControlSure({ ref,redId,nestMd });
    const onFinish = React.useCallback(async(upfile: any, del:boolean) => {
        onSure({...inp, '_FILE_S部位': upfile});
        !modified && setModified(true);
    }, [inp, modified,onSure,setModified]);
    const [uploadDom]=useUppyUpload({ repId:repId!,
        maxFile:maxFile, onFinish, storeObj: inp?._FILE_S部位
    });
    return (
        <InspectRecordLayout inp={inp} setInp={setInp}  getInpFilter={getInpFilter} show={show} redId={redId} nestMd={nestMd}
                             alone={alone}  label={label??'检查报告（附页）-附图'}>
            <InputLine label={`${memc??'缺陷附图或说明'}：`}>
                <BlobInputList value={inp?.示图说明 || ''} rows={5} datalist={datalist}
                               onListChange={v => setInp({...inp, 示图说明: v || undefined}) } />
            </InputLine>

            {children}
            {label??'附页附图'}：
            {uploadDom}
        </InspectRecordLayout>
    );
} );


